<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
	<th:block th:include="include :: header('线下采购订单')"/>
	<th:block th:include="include :: businessCSS"/>
	<style>
		.layui-table-tool-self {
			display: none;
		}

		.layui-table-tool-temp {
			padding-right: 0
		}
	</style>
</head>
<body class="no-skin">
<div class="main-container" id="main-container">
	<div class="main-content">
		<form class="layui-form head-form">
			<div class="north">
				<th:block th:include="include :: business_btn"/>
				<th:block th:include="include :: business_tpl('top')"/>
			</div>
			<div class="mid-content">
				<table class="layui-hide" id="dhtable" lay-filter="ftable"></table>
			</div>
			<th:block th:include="include :: pageFooter"/>
		</form>

	</div>
</div>
<script type="text/html" id="toolbar">
	<div style="padding: 16px;display: flex;justify-content: space-between;">
		<div style="font-weight: 700;font-size: 18px;">采购列表</div>
		<div>
			<button class="layui-btn layui-btn-normal dhicon"
					th:classappend="${enableEdit} == 1 ?'':'layui-btn-disabled'" type="button"
					th:disabled="${enableEdit} == 1 ?false:true" lay-event="addbtn" id="btn-sh">新增
			</button>
			<button class="layui-btn layui-btn-danger dhicon"
					th:classappend="${enableEdit} == 1 ?'':'layui-btn-disabled'" type="button"
					th:disabled="${enableEdit} == 1 ?false:true" lay-event="mjbtn_save" id="btn-sh">删除
			</button>
			<button class="layui-btn layui-btn-normal dhicon"
					th:classappend="${enableEdit} == 1 ?'':'layui-btn-disabled'" type="button"
					th:disabled="${enableEdit} == 1 ?false:true" lay-event="batch_edit_hw_btn" id="btn-sh">批量修改仓库信息
			</button>
		</div>
	</div>
</script>
<th:block th:include="include :: footer"/>
<th:block th:include="include :: businessJS"/>
<th:block th:include="include :: businessTableBtn"/>
<th:block th:include="include :: inlineJS"/>
<script type="text/javascript">
	var $, layer, form, table, laydate, element;//定义layui模块
	var listData1 = [];
	eachFields();//明细表格中的字段遍历


	if (!!$("#fXsFpsl_select").val()) $("#fXsFpsl").val($("#fXsFpsl_select").val());//默认税率赋值至input
	layui.use(['laydate', 'table', 'form', 'layer', 'jquery', 'util', 'element'], function () {
		$ = layui.$, layer = layui.layer, form = layui.form, table = layui.table, laydate = layui.laydate, util = layui.util, element = layui.element;
		beforeInit();//表单初始化之前的动作集合
		layui.element.render();
		$.get(moduleUrl + "/listbynid?nid=" + nid, function (data) {
			$.each(data.data, function (k, v) {
				dataStr.push(v);
			});
			listData1 = data.data
			// numall()
			initTable();//初始化表格
		});
		toolbarEvent();//通用表格头部工具栏事件监听
		toolEvent('ftable');//行event事件监听
		monitorSort();//监听排序——重载赋值渲染

		//监听单元格编辑
		table.on('edit(ftable)', function (obj) {
		});


		table.on('toolbar(ftable)', function (obj) {
			var selectedObject = ""
			table.cache.dhtable.map((v, i) => {
				if (selectedObject) {
					selectedObject += ',' + v.pGuid
				} else {
					selectedObject += v.pGuid
				}
			})
			switch (obj.event) {
				case 'addbtn':
					layer.open({
						type: 2,
						area: [($(window).width() - 200) + 'px', ($(window).height() - 100) + 'px'],
						fix: false,//不固定
						offset: '10%',//距离顶部
						maxmin: true,//最大最小化
						shade: 0.3,//遮罩
						title: '采购列表',
						content: "/purchase/offlinepurchaseorder/select2?pagetype=checkbox&by=direct&fmoduleTable=" + moduleTable + "&selectedObject=" + selectedObject,
						btn: ['确定', '取消'],
						shadeClose: true,// 弹层外区域关闭
						yes: function (index, layero) {
							console.log('click---yes');
							var res = window["layui-layer-iframe" + index].callbackdata();
							console.log("res",res)
							if (res.length > 0) {
								res.forEach(item => {
									item.orderID = item.bid
									item.sNum = item.sum
									item.goodsAllocation = ""
									item.pGuid = item.guid
									item.guid = ""
									item.inqty = 0
								});
								table.reload('dhtable', {data: res});
								layer.closeAll();
							} else {
								layer.msg("请选择数据");
							}
						}
					});
					break;
				case 'mjbtn_save':
					var objdata = table.checkStatus('dhtable')
					objdata = objdata.data
					listData1 = table.cache.dhtable;
					if (objdata.length > 0) {
						objdata.forEach(item => {
							listData1 = listData1.filter(items => items.guid != item.guid);
						});
						table.reload('dhtable', {data: listData1});
					} else {
						layer.msg("请选择数据");
					}
					break;
				case 'batch_edit_hw_btn':
					var datas = table.cache.dhtable;
					console.log('datas---', datas);
					getMore('goodsAllocationPl',null,'货位编号','tcc_goodsallocation')
					break;
			};
		});
	})
	
	window.getMoreAfter=function(fieldsList,fields,tindex,fieldName,fieldSearchType,isSearch,isLayer,res){
		var datasAll = layui.table.cache.dhtable;
		if ( fields == 'goodsAllocationPl'){
			var rows = [];
            for (var i = 0; i < datasAll.length; i++) {
            	var row = datasAll[i];
            	row.goodsAllocation = res.goodsAllocation;
            	row.goodsArea = res.goodsArea;
            	row.warehouseAddress = res.warehouseAddress;
            	rows.push(row);
            }
            layui.table.reload('dhtable', {data: rows});
		}

	}
</script>
</body>
</html>
